<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
   <head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
   <meta name="description" content="requirement" />
   <meta name="keywords" content="requirement" />
   <meta name="author" content="Benny Saxen" />
   <link rel="stylesheet" type="text/css" href="reqtool.css" title="M2M-ARH" media="screen,projection" />
<?php
include("reqtool-lib.php");
//=============================================================================
if (!is_dir("db"))
{
   echo("Database directory created<br>");
   mkdir("db");
   createDb("REQTOOL_DB");
   createFile("db-list.txt","REQTOOL_DB\n");
} 

session_start(); 
$s_db1    = $_SESSION['s_db1'];
if (!is_dir("db/$s_db1")) $s_db1 = '-'; 
$s_req1   = $_SESSION['s_req1'];
$s_db2    = $_SESSION['s_db2'];
if (!is_dir("db/$s_db2")) $s_db2 = '-'; 
$s_req2   = $_SESSION['s_req2'];

$s_year  = $_SESSION['s_year'];
$s_month = $_SESSION['s_month'];
$s_day   = $_SESSION['s_day'];

if(!$s_day)
{
    $s_day    = date('d');
    $s_month  = date('m');
    $s_year   = date('Y');
}

echo("<title>ReqTool</title></head>");

echo("
<STYLE type=text/css>
A:link {COLOR: blue;text-decoration:none;}
A:visited {COLOR: blue}
A:hover {COLOR: green}
BODY {COLOR: black} 
body {background-color:#grey;}
</STYLE>
");
//==============================================================================
$action = $_GET['action'];

if($action == 'selectDb1')
{
  $s_db1 = $_POST['db_id'];
}

if($action == 'selectDb2')
{
  $s_db2 = $_POST['db_id'];
}

if($action == 'selectReq1')
{
  $s_req1 = $_GET['req_id'];
}
if($action == 'selectReq2')
{
  $s_req2 = $_GET['req_id'];
}

if($action == 'saveReq')
{
   $db   = $_GET['db_id'];
   $req  = $_GET['req_id'];
   $text = $_POST['req_text'];
   saveReq($db,$req,$text);
}
if($action == 'addReq1')
{
$temp = $_POST['req_text'];
if($temp)
  {
    addReq($s_db1,$temp);
  }
}
if($action == 'addReq2')
{
$temp = $_POST['req_text'];
if($temp)
  {
    addReq($s_db2,$temp);
  }
}

if($action == 'createDb')
{
$temp = $_POST['db_id'];
if($temp)
  {
    echo("Create db:");
    echo("<br>$temp<br>");
    createDb($temp);
  }
}



$_SESSION['s_db1']  = $s_db1;
$_SESSION['s_req1'] = $s_req1;
$_SESSION['s_db2']  = $s_db2;
$_SESSION['s_req2'] = $s_req2;
if($s_db1 && $s_req1) $s_text1 = getReqText($s_db1,$s_req1);
if($s_db2 && $s_req2) $s_text2 = getReqText($s_db2,$s_req2);
//==============================================================================
echo("<body>");
$mode = 1;
if($mode==1)
{
echo("<div align=\"center\" id=\"container\" style=\"background-color:#b010000; color: #0900C4; font: Helvetica 12pt;border: 1px solid black;\">");

echo("<div align=\"left\" id=\"top\" style=\"background-color:cornsilk; color: #0900C4; font: Helvetica 12pt;border: 1px solid blue;\">");
echo("<h2>Requirement Tool</h2>");
//echo("admin link");
echo("</div>");
//===================================================================
echo("<div align=\"left\" id=\"left\" style=\"float:left; width:48%; background-color:grey; color: #0900C4; font: Helvetica 12pt;border: 1px solid gren;\">");
echo("<form method=\"post\" action=\"index.php?action=selectDb1\" >
<select name=\"db_id\">
");
listAllDbSelect($s_db1);
echo("
</select>
<input type=\"submit\" value=\"Select Database\" > 
</form>
");

//listAllReq2($s_db1);
showAllReq(1,$s_db1,$s_req1);
echo("</div>");
//===================================================================
echo("<div align=\"left\" id=\"right\" style=\"float:right; width:48%; background-color:grey; color: #0900C4; font: Helvetica 12pt;border: 1px solid red;\">");
echo("<form method=\"post\" action=\"index.php?action=selectDb2\" >
<select name=\"db_id\">
");
listAllDbSelect($s_db2);
echo("
</select>
<input type=\"submit\" value=\"Select Database\" > 
</form>
");
//listAllReq2($s_db2);
showAllReq(2,$s_db2,$s_req2);
echo("</div>");
//===================================================================
echo("</div>");
}

if($mode==2)
{
// create db form
echo("
<form method=\"post\" action=\"index.php?action=createDb\" >
<input type=\"text\" name=\"db_id\" size=\"20\" value=\"\"><br>
<input type=\"submit\" value=\"Create Database\" > 
</form>
");
// Add requirement form
echo("
<form method=\"post\" action=\"index.php?db=$s_db&action=addReq\" >
<textarea cols=\"80\" rows=\"5\" name=\"req_text\">
");
echo("$s_text");
echo("
</textarea>
<br><input type=\"submit\" value=\"Add Requirement\" > 
</form>
");
listAllDb2();

}
echo("</body></html>");
